草庐IT

Python Django 模板 : Iterate Through List

全部标签

c++ - 派生模板类访问基类成员数据

这个问题是对thisthread中提出的问题的进一步插入.使用以下类定义:templateclassFoo{public:Foo(constfoo_arg_tfoo_arg):_foo_arg(foo_arg){/*dosomethingforfoo*/}TFoo_T;//eitheraTypeAoraTypeB-TBDfoo_arg_t_foo_arg;};templateclassBar:publicFoo{public:Bar(constfoo_arg_tbar_arg,consta_arg_ta_arg):Foo(bar_arg)//base-classinitializer{

c++ - 模板成员函数重载问题

N4296::13.1/2.2[over.load]的标准说:Likewise,memberfunctiontemplatedeclarationswiththesamename,thesameparameter-type-list,andthesametemplateparameterlistscannotbeoverloadedifanyofthemisastaticmemberfunctiontemplatedeclaration.所以,我认为下面的程序是病式的:#includestructA{templatestaticvoidfoo(){}templatestaticintf

c++ - 使用可变参数模板的递归继承

考虑以下代码:#includestructActionOption{virtualvoidfoo(int)const=0;};templatestructActionType;templatestructActionType:ActionOption{virtualvoidfoo(int)constoverride{std::cout::foo(int)called.\n";}};templatestructActionType:ActionOption{virtualvoidfoo(int)constoverride{std::cout::foo(int)called.\n";}};

c++ - 配对从可变参数模板中随机获得的兼容类型

ABow只能发射Missile类型Arrow,Bolt,或Dart(但不是Stone),并且只能与MissileContainer一起使用类型Quiver或Case.Quiver只能装箭或bolt,而Case只能装bolt、飞镖或石头。我已经声明了这一点:structBow:MissileFireWeapon,MissileTypes,MissileContainerTypes{/*...*/};structQuiver:MissileContainer,MissileTypes{};structCase:MissileContainer,MissileTypes{};在哪里templ

已编译但未使用的 C++ 模板 - mac OS Lion

我有一个非常非常奇怪的情况。我编写的代码看起来像这样:classFoo{public:templateintdoSomething(){std::cout如果我尝试像这样调用doSomething:std::cout();std::cout输出:PrePost我没有得到HelloWorld的输出,函数中的任何内容都没有执行。这自然意味着我的程序稍后会崩溃,因为我需要执行该函数。但是,如果我进行模板特化:templateintdoSomething(){std::cout那么我的输出是:PreHelloWorldint!Post这不会发生在Windows或Linux上,只会发生在Mac上

c++ - 用于逻辑拆分的非类型模板

我有以下情况,不知道我的做法对不对。我正在从事具有以下结构的项目:classFilesystem{public:Filesystem(Profile*profile);OpenFile(conststd::string&file,OpenFileCallback);ReadFile(intfile_handle,Buffer*buffer,ulongoffset,ulonglength);protected:DiskRouter*disk_router_;...}//---implementation---Filesystem::Filesystem(Profile*profile):

c++ - 与构建灵活设计的模板相比,多重继承机制

这是question的缩小版本由于范围太广而搁置。在ModernC++Design的第6-7页,AndreiAlexandrescu列出了三种多重继承弱于模板的方式构建灵活的设计。他特别指出,多重继承提供的机制很差(方括号中的文本和格式是我根据我对上下文):Insuchasetting[i.e.multipleinheritance],[tobuildaflexibleSmartPtr,]theuserwouldbuildamultithreaded,reference-countedsmartpointerclassbyinheritingsomeBaseSmartPtrclassa

c++ - 模板代码膨胀是否仍然是最新编译器/链接器的问题

我读到最新版本的链接器清除了多个翻译单元中的重复定义,解决了与模板有关的代码膨胀问题。因此,即使我使用编译的包含模型,我使用模板的代码也不应该导致代码膨胀。我的查询是关于这样的模板(元编程)的使用:templateintfact(){returnfact()*N;}templateintfact(){return1;}intmain(){cout()上述代码的exe大小约为8K。如果我传递100而不是10,代码大小将增加到19K。基本上,我试图了解在使用模板时可能导致代码膨胀的编码模式。编辑:在Yakk的评论之后,我使用-O3重新编译,现在大小几乎相同。我的问题是,使用模板(使用最新的

c++ - 使用类型别名的可变参数模板推导

我有这样一个程序:templateusingFunction=void(*)(Args*...);templatevoidDoThing(Functionfunc){}voidIntFunction(int*i){}intmain(intargc,char*argv[]){DoThing(IntFunction);}当我运行程序时出现这个错误$clang++-std=c++14template.cpptemplate.cpp:12:3:error:nomatchingfunctionforcallto'DoThing'DoThing(IntFunction);^~~~~~~templa

C++11 "overloaded lambda"带有可变参数模板和变量捕获

我正在研究一个可能被称为“重载lambda”的C++11习语:http://cpptruths.blogspot.com/2014/05/fun-with-lambdas-c14-style-part-2.htmlhttp://martinecker.com/martincodes/lambda-expression-overloading/使用可变参数模板重载n函数似乎对我很有吸引力,但事实证明它不适用于变量捕获:[&]中的任何一个|[=][y][&y](和[this]等,如果在成员函数中)导致编译失败:error:nomatchforcallto'(overload,main(in